import pinia from '@/store/store.js';
import { useIndexStore } from '@/store/model/index.js'
const store = useIndexStore(pinia);

(()=>{
    //禁止客户端修改storage里面的数据
    window.addEventListener('storage', (e) => {
        localStorage.setItem(e.key, e.oldValue);
    });

    //禁止客户端随意缩放
    var t = window.devicePixelRatio;
    document.body.style.zoom = 1 / t;

    document.addEventListener(
        'keydown',
        function (event) {
            if (
                (event.ctrlKey === true || event.metaKey === true) &&
                (event.which === 61 ||
                    event.which === 107 ||
                    event.which === 173 ||
                    event.which === 109 ||
                    event.which === 187 ||
                    event.which === 189)
            ) {
                event.preventDefault();
            }
        },
        false
    );

    // Chrome IE 360
    window.addEventListener(
        'wheel',
        function (event) {
            if (event.ctrlKey === true || event.metaKey) {
                event.preventDefault();
            }
        },
        {
            passive: false,
        }
    );

    window.addEventListener(
        'DOMMouseScroll',
        function (event) {
            if (event.ctrlKey === true || event.metaKey) {
                event.preventDefault();
            }
        },
        {
            passive: false,
        }
    );

    //设置页面响应式，修改根标签的fontsize
    function setHtml() {
        let cWidth =
            document.body.clientWidth || document.documentElement.clientWidth;
        let target = cWidth / 19.2;
        document.documentElement.style.fontSize = target + 'px';
    }
    setHtml();
    //设置根标签的宽度为1920px
    // document.documentElement.style.width = 19.2 + "rem"
    window.addEventListener('resize', function () {
        setHtml();
        let width = window.innerWidth;
        let height = window.innerHeight;
        let win = width / height;
        let sp = 1440 / 3120
        let hp = 1920 / 1080
        let distanceToSp = Math.abs(win - sp);
        let distanceToHp = Math.abs(win - hp);
        // 当前屏幕的宽高比例更接近于distanceToSp
        if(distanceToSp < distanceToHp ){
            store.update_img_src(require('@/assets/img/bg_sp.mp4'));
        }else{
            store.update_img_src(require('@/assets/img/bg_hp.mp4'));
        }
    });
})();
